using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;

namespace Musicman.Entities.BusinessEntities
{
    public class SearchJobConfigurationElementCollection : ConfigurationElementCollection
    {
        
        public SearchJobConfigurationElementCollection()
        {
            SearchJobConfigurationElement job = (SearchJobConfigurationElement)CreateNewElement();
            Add(job);
        }

        public override ConfigurationElementCollectionType CollectionType
        {
            get
            {
                return ConfigurationElementCollectionType.AddRemoveClearMap;
            }
        }

        protected override ConfigurationElement CreateNewElement()
        {
            return new SearchJobConfigurationElement();
        }
       
        protected override Object GetElementKey(ConfigurationElement element)
        {
            return String.Format("{0}_{1}", ((SearchJobConfigurationElement)element).Name, ((SearchJobConfigurationElement)element).Stype);
        }

        public new string AddElementName
        {
            get
            { return base.AddElementName; }

            set
            { base.AddElementName = value; }

        }

        public new string ClearElementName
        {
            get
            { return base.ClearElementName; }

            set
            { base.AddElementName = value; }

        }

        public new string RemoveElementName
        {
            get
            { return base.RemoveElementName; }
        }

        public new int Count
        {
            get { return base.Count; }
        }

        public SearchJobConfigurationElement this[int index]
        {
            get
            {
                return (SearchJobConfigurationElement)BaseGet(index);
            }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }

        new public SearchJobConfigurationElement this[string Name]
        {
            get
            {
                return (SearchJobConfigurationElement)BaseGet(Name);
            }
        }

        public int IndexOf(SearchJobConfigurationElement job)
        {
            return BaseIndexOf(job);
        }

        public void Add(SearchJobConfigurationElement job)
        {
            BaseAdd(job);
        }

        protected override void BaseAdd(ConfigurationElement element)
        {
            BaseAdd(element, false);
        }

        public void Remove(SearchJobConfigurationElement job)
        {
            if (BaseIndexOf(job) >= 0)
            {
                BaseRemove(String.Format("{0}_{1}", job.Name, job.Stype));
            }
        }

        public void RemoveAt(int index)
        {
            BaseRemoveAt(index);
        }

        public void Remove(string name)
        {
            BaseRemove(name);
        }

        public void Clear()
        {
            BaseClear();
        }
        
        public override bool IsReadOnly()
        {
            return false;
        }
    }
}
